package com.jx.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jx.dao.FindFuncsDao;
import com.jx.model.Func;
import com.jx.util.JDBCUtil;

public class FindFuncsDaoImpl implements FindFuncsDao {
	/**
	 * 查询出所有的功能
	 * @param start
	 * @param pagesize
	 * @return
	 */
	@Override
	public List<Func> findFuncsDao(int start,int pagesize) {
		// TODO Auto-generated method stub
		List<Func> funcs=new ArrayList<Func>();
		Connection con=JDBCUtil.getConnection();
		StringBuffer sql=new StringBuffer("select * from j_func limit ?,?");
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			pst.setInt(1, start);
			pst.setInt(2, pagesize);
			ResultSet res=pst.executeQuery();
			while(res.next()){
				Func func=new Func(res.getInt("fid"),res.getString("fname"),res.getString("fdes"),res.getInt("fparentid"),res.getString("fstate"),res.getString("fpath"));
				funcs.add(func);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return funcs;
	}
	/**
	 * 查询出所有的功能总数
	 */
	@Override
	public int findTotalFuncs() {
		// TODO Auto-generated method stub
		int total=0;
		Connection con=JDBCUtil.getConnection();
		StringBuffer sql=new StringBuffer("select count(fid) ftotal from j_func");
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			ResultSet res=pst.executeQuery();
			if(res.next()){
				total=res.getInt("ftotal");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return total;
	}

}
